package com.example.vue.controller;

import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : liuf
 * @version V1.0
 * @title: GoodsDetailController
 * @date 2025年06月08日 15:41
 **/
@RestController
@RequestMapping("/api")
public class GoodsDetailController {

    @GetMapping("/goods/detail/{id}")
    public ApiResponse<SkuDetailData> getSkuDetail(@PathVariable Long id) {
        // 1. 创建分类视图数据
        CategoryView categoryView = new CategoryView();
        categoryView.setId(61L);
        categoryView.setCategory1Id(2L);
        categoryView.setCategory1Name("手机");
        categoryView.setCategory2Id(13L);
        categoryView.setCategory2Name("手机通讯");
        categoryView.setCategory3Id(61L);
        categoryView.setCategory3Name("手机");

        // 2. 创建销售属性列表
        List<SpuSaleAttr> spuSaleAttrList = new ArrayList<>();

        // 颜色属性
        SpuSaleAttr colorAttr = new SpuSaleAttr();
        colorAttr.setId(1L);
        colorAttr.setSpuId(1L);
        colorAttr.setBaseSaleAttrId(1L);
        colorAttr.setSaleAttrName("选择颜色");

        List<SpuSaleAttrValue> colorValues = new ArrayList<>();
        SpuSaleAttrValue blackColor = new SpuSaleAttrValue();
        blackColor.setId(1L);
        blackColor.setSpuId(1L);
        blackColor.setBaseSaleAttrId(1L);
        blackColor.setSaleAttrValueName("黑色");
        blackColor.setSaleAttrName("选择颜色");
        blackColor.setIsChecked("1");
        colorValues.add(blackColor);
        SpuSaleAttrValue blackColor1 = new SpuSaleAttrValue();
        blackColor1.setId(2L);
        blackColor1.setSpuId(1L);
        blackColor1.setBaseSaleAttrId(1L);
        blackColor1.setSaleAttrValueName("金色");
        blackColor1.setSaleAttrName("选择颜色");
        blackColor1.setIsChecked("0");
        colorValues.add(blackColor1);
        // 可以添加其他颜色...

        colorAttr.setSpuSaleAttrValueList(colorValues);
        spuSaleAttrList.add(colorAttr);

        // 版本属性
        SpuSaleAttr versionAttr = new SpuSaleAttr();
        versionAttr.setId(2L);
        versionAttr.setSpuId(1L);
        versionAttr.setBaseSaleAttrId(2L);
        versionAttr.setSaleAttrName("选择版本");

        List<SpuSaleAttrValue> versionValues = new ArrayList<>();
        SpuSaleAttrValue gb64 = new SpuSaleAttrValue();
        gb64.setId(4L);
        gb64.setSpuId(1L);
        gb64.setBaseSaleAttrId(2L);
        gb64.setSaleAttrValueName("64GB");
        gb64.setSaleAttrName("选择版本");
        gb64.setIsChecked("1");
        versionValues.add(gb64);
        SpuSaleAttrValue gb128 = new SpuSaleAttrValue();
        gb128.setId(5L);
        gb128.setSpuId(1L);
        gb128.setBaseSaleAttrId(2L);
        gb128.setSaleAttrValueName("128GB");
        gb128.setSaleAttrName("选择版本");
        gb128.setIsChecked("0");
        versionValues.add(gb128);
        // 可以添加其他版本...

        versionAttr.setSpuSaleAttrValueList(versionValues);
        spuSaleAttrList.add(versionAttr);

        // 套装属性
        SpuSaleAttr packageAttr = new SpuSaleAttr();
        packageAttr.setId(3L);
        packageAttr.setSpuId(1L);
        packageAttr.setBaseSaleAttrId(3L);
        packageAttr.setSaleAttrName("选择套装");

        List<SpuSaleAttrValue> packageValues = new ArrayList<>();
        SpuSaleAttrValue standard = new SpuSaleAttrValue();
        standard.setId(7L);
        standard.setSpuId(1L);
        standard.setBaseSaleAttrId(3L);
        standard.setSaleAttrValueName("官方标配");
        standard.setSaleAttrName("选择套装");
        standard.setIsChecked("0");
        packageValues.add(standard);
        SpuSaleAttrValue standard1 = new SpuSaleAttrValue();
        standard1.setId(8L);
        standard1.setSpuId(1L);
        standard1.setBaseSaleAttrId(3L);
        standard1.setSaleAttrValueName("豪华套装");
        standard1.setSaleAttrName("选择套装");
        standard1.setIsChecked("1");
        packageValues.add(standard1);
        // 可以添加其他套装...

        packageAttr.setSpuSaleAttrValueList(packageValues);
        spuSaleAttrList.add(packageAttr);

        // 3. 创建SKU信息
        SkuInfo skuInfo = new SkuInfo();
        skuInfo.setId(2L);
        skuInfo.setSpuId(1L);
        skuInfo.setPrice(new BigDecimal("5499"));
        skuInfo.setSkuName("Apple iPhone 11 (A2223) 64GB 红色 移动联通电信双卡双待");
        skuInfo.setSkuDesc("主体\n入网型号\nA2223\n品牌\nApple\n产品名称\niPhone 11\n上市年份\n2019年\n上市月份\n9月\n基本信息\n机身颜色\n红色\n机身长度（mm）\n150.9\n机身重量（g）\n194\n机身材质工艺\n以官网信息为准\n机身宽度（mm）\n75.7\n机身材质分类\n玻璃后盖\n机身厚度（mm）\n8.3\n运营商标志或内容\n无");
        skuInfo.setWeight("0.47");
        skuInfo.setTmId(1L);
        skuInfo.setCategory3Id(61L);
        skuInfo.setSkuDefaultImg("https://img13.360buyimg.com/n7/jfs/t1/319946/33/6083/39060/683ede35F7de500fa/c690fc1da56954f4.png");
        skuInfo.setIsSale(1);

        // SKU图片列表
        List<SkuImage> skuImageList = new ArrayList<>();
        SkuImage image1 = new SkuImage();
        image1.setId(6L);
        image1.setSkuId(2L);
        image1.setImgName("63e862164165f483.jpg");
        image1.setImgUrl("https://img13.360buyimg.com/n7/jfs/t1/319946/33/6083/39060/683ede35F7de500fa/c690fc1da56954f4.png");
        image1.setSpuImgId(2L);
        image1.setIsDefault("0");
        skuImageList.add(image1);
        SkuImage image2 = new SkuImage();
        image2.setId(7L);
        image2.setSkuId(2L);
        image2.setImgName("63e862164165f483.jpg");
        image2.setImgUrl("https://img13.360buyimg.com/n5/s114x114_jfs/t1/47718/25/21265/7394/63191e2cEa5b684d9/772b3cf0ba95e12a.jpg.avif");
        image2.setSpuImgId(2L);
        image2.setIsDefault("0");
        skuImageList.add(image2);
        SkuImage image3 = new SkuImage();
        image3.setId(8L);
        image3.setSkuId(2L);
        image3.setImgName("63e862164165f483.jpg");
        image3.setImgUrl("https://img13.360buyimg.com/n5/s114x114_jfs/t1/199162/36/26401/30450/63191e30E283ebb8c/80759c310e6247cb.jpg.avif");
        image3.setSpuImgId(2L);
        image3.setIsDefault("0");
        skuImageList.add(image3);
        // 可以添加其他图片...

        skuInfo.setSkuImageList(skuImageList);

        // SKU属性值列表
        List<SkuAttrValue> skuAttrValueList = new ArrayList<>();
        SkuAttrValue attrValue1 = new SkuAttrValue();
        attrValue1.setId(6L);
        attrValue1.setAttrId(1L);
        attrValue1.setValueId(6L);
        attrValue1.setSkuId(2L);
        skuAttrValueList.add(attrValue1);
        // 可以添加其他属性值...

        skuInfo.setSkuAttrValueList(skuAttrValueList);
        skuInfo.setSkuSaleAttrValueList(null);

        // 4. 创建返回数据
        SkuDetailData data = new SkuDetailData();
        data.setValuesSkuJson("{\"3|5|7\":6,\"3|4|7\":2,\"2|4|7\":3,\"1|5|7\":5,\"1|4|7\":1,\"2|5|7\":4}");
        data.setPrice(new BigDecimal("5499"));
        data.setCategoryView(categoryView);
        data.setSpuSaleAttrList(spuSaleAttrList);
        data.setSkuInfo(skuInfo);

        // 5. 返回API响应
        return new ApiResponse<>(200, "成功", data, true);
    }

}

@Data
class CategoryView {
    private Long id;
    private Long category1Id;
    private String category1Name;
    private Long category2Id;
    private String category2Name;
    private Long category3Id;
    private String category3Name;

    // 构造方法、getters和setters
    // ...
}

@Data
class SpuSaleAttrValue {
    private Long id;
    private Long spuId;
    private Long baseSaleAttrId;
    private String saleAttrValueName;
    private String saleAttrName;
    private String isChecked;

    // 构造方法、getters和setters
    // ...
}

@Data
class SpuSaleAttr {
    private Long id;
    private Long spuId;
    private Long baseSaleAttrId;
    private String saleAttrName;
    private List<SpuSaleAttrValue> spuSaleAttrValueList;

    // 构造方法、getters和setters
    // ...
}

@Data
class SkuImage {
    private Long id;
    private Long skuId;
    private String imgName;
    private String imgUrl;
    private Long spuImgId;
    private String isDefault;

    // 构造方法、getters和setters
    // ...
}

@Data
class SkuAttrValue {
    private Long id;
    private Long attrId;
    private Long valueId;
    private Long skuId;

    // 构造方法、getters和setters
    // ...
}

@Data
class SkuInfo {
    private Long id;
    private Long spuId;
    private BigDecimal price;
    private String skuName;
    private String skuDesc;
    private String weight;
    private Long tmId;
    private Long category3Id;
    private String skuDefaultImg;
    private Integer isSale;
    private List<SkuImage> skuImageList;
    private List<SkuAttrValue> skuAttrValueList;
    private List<?> skuSaleAttrValueList;

    // 构造方法、getters和setters
    // ...
}

@Data
class ApiResponse<T> {
    private Integer code;
    private String message;
    private T data;
    private Boolean ok;

    public ApiResponse(Integer code, String message, T data, Boolean ok) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.ok = ok;
    }

    // getters和setters
    // ...
}

@Data
class SkuDetailData {
    private String valuesSkuJson;
    private BigDecimal price;
    private CategoryView categoryView;
    private List<SpuSaleAttr> spuSaleAttrList;
    private SkuInfo skuInfo;

    // 构造方法、getters和setters
    // ...
}

